import unittest
from google.appengine.ext import ndb
from ndb_nl_sort.model.unnatural_name import UnnaturalName

__author__ = 'raulg'


def prop_query(obj, prop_name):
    prop = getattr(obj, prop_name)

    property_dict = getattr(obj, '_properties', dict())

    is_property = False
    is_not_computed_property = True
    if prop_name in property_dict:
        prop_type = property_dict[prop_name]
        is_property = isinstance(prop_type, ndb.model.Property)
        is_not_computed_property = not isinstance(prop_type, ndb.ComputedProperty)

    return is_property and is_not_computed_property


class SetterTest(unittest.TestCase):
    def test_entity(self):
        the_entity = UnnaturalName(name='Flavor-99')

        self.assertTrue(prop_query(the_entity, 'name'))
        self.assertFalse(prop_query(the_entity, 'natural_name'))
